package com.ltedu.course.controller;


import com.ltedu.common.contants.Constants;
import com.ltedu.common.validate.Create;
import com.ltedu.common.vo.Result;
import com.ltedu.course.domain.Video;
import com.ltedu.course.domain.vo.VideoVO;
import com.ltedu.course.service.VideoService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * <p>
 * 课程视频表 前端控制器
 * </p>
 *
 * @author Jerry
 * @since 2020-12-10
 */
@RestController
@RequestMapping("/course/video")
public class VideoController {

    @Autowired
    private VideoService videoService;

    /**
     * 添加视频小节
     *
     * @param videoVO 视频签证官
     * @return {@link Result}
     */
    @PostMapping("/add")
    public Result add(@Validated(Create.class) @RequestBody VideoVO videoVO) {
        Video video = new Video();
        BeanUtils.copyProperties(videoVO, video);
        video.setState(Constants.NORMAL);
        video.setGmtCreate(new Date());
        video.setGmtModified(new Date());
        return Result.ok(videoService.save(video));
    }
}

